package donjuan;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
//在用户已经存在数据表示，展示数据库中所有数据表，让用户挑选指定数据表
public class Window_present extends JPanel implements ActionListener {
  JButton done = new JButton("结束");
  
  JButton perform = new JButton("查询");
  
  JTextArea contents = new JTextArea(11, 45);
  
  JSplitPane[] frame = new JSplitPane[6];
  
  JTextField scan = new JTextField(20);
  
  Window_present() {
    setVisible(true);
    setBounds(50, 50, 300, 300);
    setName("请输入信息");
    setLayout(new FlowLayout());
    init();
  }
  
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == this.done) {
      Window_ready.contain[2] = this.scan.getText();
      Window_main.mode = 6;
      Window_main.jump();
      Message.activatesql();
    } else if (e.getSource() == this.scan) {
      Window_ready.contain[2] = this.scan.getText();
    } else if (e.getSource() == this.perform) {
      try {
        DatabaseMetaData databaseMetaData = Message.con.getMetaData();
        String[] types = { "TABLE" };
        ResultSet rs = databaseMetaData.getTables(Message.con.getCatalog(), null, "%", types);
        for (; rs.next(); this.contents.append("表名："+ rs.getString(3) + "\n"));
        Window_ready.contain[2] = "test1";
        Message.Link_start = Boolean.valueOf(true);
      } catch (SQLException e1) {
        System.exit(-1);
      } 
    } 
  }
  
  void init() {
    this.scan.setPreferredSize(new Dimension(20, 40));
    this.done.setPreferredSize(new Dimension(200, 40));
    this.perform.setPreferredSize(new Dimension(200, 40));
    this.done.addActionListener(this);
    this.perform.addActionListener(this);
    this.scan.addActionListener(this);
    this.frame[0] = new JSplitPane(0, this.scan, this.contents);
    this.frame[1] = new JSplitPane(1, this.done, this.perform);
    this.frame[0].setPreferredSize(new Dimension(400, 300));
    this.frame[2] = new JSplitPane(0, this.frame[0], this.frame[1]);
    add(this.frame[2]);
  }
}
